package com.yc.jpyy.mobile.controller;

import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yc.jpyy.base.bean.RestResponse;
import com.yc.jpyy.base.controller.BaseController;
import com.yc.jpyy.mobile.dao.BizDao;
import com.yc.jpyy.mobile.service.BizService;

@Controller
@RequestMapping(value = "/student")
public class AddFeedBackController extends BaseController {
	
	@Autowired
	private BizService bizService;

	@Autowired
	private BizDao bizDao;
	private static Logger logger = LoggerFactory.getLogger(AddFeedBackController.class);
	/**
	 * 添加意见反馈信息
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/addFeedBack", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
	public @ResponseBody String addFeedBack(HttpServletRequest request)
			throws UnsupportedEncodingException {

		RestResponse response = new RestResponse();
		request.setCharacterEncoding("UTF-8");

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			//标题
			String title = request.getParameter("title");
			//内容
			String content = request.getParameter("content");
			//联系方式
			String contact = request.getParameter("contact");
			//数据类型
			//String dataType = request.getParameter("dataType");
			//学员ID
			//String studentId = request.getParameter("studentId");
			//驾校ID
			//String driverId = request.getParameter("driverId");
			//用户ID
			//String userId = request.getParameter("userId");
			if((null !=content && !content.isEmpty())){
				Map<String, Object> valMap = new HashMap<String, Object>();
				// 添加建议
				valMap.put("Title", title);
				valMap.put("FContent", content);
				valMap.put("Contact", contact);
				//valMap.put("dataType", dataType);
				//valMap.put("userId", userId);
				//valMap.put("studentId", studentId);
				//valMap.put("driverId", driverId);
				valMap.put("CreateTime", sdf.format(new Date()));
				int i = bizService.addFeedBack(valMap);
				if (i > 0) {
					response.setMessage("感谢您的意见反馈，我们将尽力完善系统!");
				} else {
					response.setErrorcode(1);
					response.setMessage("意见反馈提交失败!");
				}
			}else{
				response.setErrorcode(1);
				response.setMessage("缺少必填参数!");
			}
		} catch (Exception e) {
			logger.info("addFeedBack："+ e.toString());
			response.setErrorcode(1);
			response.setMessage("反馈失败，请稍候重试！");
		} finally {
			return response.toJSON();
		}

	}

}
